<?php if (!defined('SYSTEM_ROOT')) { die('Insufficient Permissions'); }



$ss = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
$ms = mktime(0,0,0,date('m'),date('d')-30,date('Y'));

class index{
    static function today($method){
        switch($method){

            case 'out':
                global $m;
                $now = time();
                $ts = mktime(0,0,0,date('m'),date('d'),date('Y'));
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` != '存入' AND `date` >= {$ts} AND `date` <= {$now}"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            case 'in':
                global $m;
                $now = time();
                $ts = mktime(0,0,0,date('m'),date('d'),date('Y'));
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` = '存入' AND `date` >= {$ts} AND `date` <= {$now}"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            default:
                break;
        }
    }
    static function week($method){
        switch($method){
            case 'out':
                global $m;
                $now = time();
                $ss = mktime(0,0,0,date('m'),date('d') - 7,date('Y'));
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` != '存入' AND `date` >= {$ss} AND `date` <= {$now}"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            case 'in':
                global $m;
                $now = time();
                $ss = mktime(0,0,0,date('m'),date('d') - 7,date('Y'));
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` = '存入' AND `date` >= {$ss} AND `date` <= {$now}"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            default:
                break;
        }
    }
    static function month($method){
        switch($method){
            case 'out':
                global $m;
                $now = time();
                $ms = mktime(0,0,0,date('m'),date('d') - 30,date('Y'));
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` != '存入' AND `date` >= {$ms} AND `date` <= {$now}"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            case 'in':
                global $m;
                $now = time();
                $ms = mktime(0,0,0,date('m'),date('d') - 30,date('Y'));
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` = '存入' AND `date` >= {$ms} AND `date` <= {$now}"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            default:
                break;
        }
    }
    static function all($method){
        switch($method){
            case 'out':
                global $m;
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` != '存入'"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            case 'in':
                global $m;
                $x = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` = '存入'"));
                return $x['num'] > 0 ? $x['num'] : 0 ;
                break;
            case 'money':
                global $m;
                $x1 = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` = '存入'"));
                $x2 = $m->fetch_array($m->query("SELECT SUM(money) AS `num` FROM `".DB_NAME."`.`".DB_PREFIX."record` WHERE `mode` != '存入'"));
                return $x1['num'] - $x2['num'];
                break;
            default:
                break;
        }
    }
}
?>